package com.yylending.remotevideo;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by HenryZhang on 2017/4/12.<br>
 * Copyright © 2017 www.yylending.com. All Rights Reserved.<br><br>
 */
public class VideoModel extends Model {
	private static final String TAG = "VideoModel";

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		String number = (String) params;
		Service service = (Service) NetworkHelper.createService(Service.class);
		return service.sign(Global.TOKEN, new Sign(number));
	}

	@Override
	public void onNext(Object entity) {
		CLog.i(TAG, "result = " + entity);
		SignResult list = cast(entity);
		EventAgent.post(list);
	}

	private interface Service {
		@POST("anychat/sign/get")
		Observable<SignResult> sign(@Header("token") String token, @Body Sign params);
	}

	public static class Sign {
		public String userName;// = Global.USER_NAME;
		public String appid = Global.ANY_CHAT_APP_ID;
		public Sign(String number) {
			userName = number;
		}
	}

	public static class SignResult extends BaseResultEntity<Result> {}

	public static class Result {
		public long timestamp;
		public String sigStr;
		public int errorcode;
		public String appId;
	}
}
